class User{
  constructor(public id: number, public name: string) { }
}

interface Repository<T>{
  findById(id: number): T | undefined;
  save(item: T): void;
  delete(item: T): boolean;
}

class UserRepository implements Repository<User>{
  private users = new Map<number, User>;

  findById(id: number): User | undefined {
    return this.users.get(id);
  }

  save(item: User): void {
    this.users.set(item.id, item);
  }

  delete(item: User): boolean {
    return this.users.delete(item.id);
  }
}

const userRepository = new UserRepository();
userRepository.save(new User(1, "jack"));
userRepository.save(new User(2, "rose"));